package cn.java79.quiz.service;

import cn.java79.quiz.dao.AdminMapper;
import cn.java79.quiz.entity.Admin;
import cn.java79.quiz.pojo.AjaxPage;
import cn.java79.quiz.util.MybatisUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class AdminService {
    public static final int PAGESIZE=10;
    @Autowired
    AdminMapper mapper;
    public AjaxPage<Admin> search(String loginname, String realname, int pageNo){
        return this.search(loginname, realname, pageNo,PAGESIZE);
    }
    public AjaxPage<Admin> search(String loginname, String realname, int pageNo, int pageSize){


        Page<Admin> page = PageHelper.startPage(pageNo, pageSize);

            mapper.search(loginname,realname);
            //System.out.println(page.getPageNum()+">>>>>>>>>>>>>>>>>>>>>>>>>>");
            return new AjaxPage<Admin>(page.subList(0, page.size()), page.getTotal(), page.getPageNum(), page.getPageSize(), page.getPages());


    }
    public Admin login(String login, String pass){

            return  mapper.login(login,pass);

    }


//    public int del(Long id) {
//        return (int) (Math.random()*2);
//    }
}
